import Taro, { Component, useState } from '@tarojs/taro';
import { View, Button, Text, Image, Picker } from '@tarojs/components';
import Next from '../../static/user/icon_next.png';

import './index.scss';

const SexStatus = ['未知', '男', '女'];

const SexSelector = ['男', '女'];

function User() {

  const [userInfo, setUserInfo] = useState(Taro.getStorageSync('userInfo'));

  function goEdit() {
    Taro.navigateTo({
      url: `/subPackageWork/pages/edit-info/index`
    })
  }

  function handleSex(e) {
    setUserInfo({
      ...userInfo,
      sex: Number(e.detail.value)
    })
  }

  // function logout() {
  //   Taro.removeStorageSync('userInfo')
  //   Taro.removeStorageSync('isGetScopeUserInfo')
  //   Taro.removeStorageSync('token')
  //   Taro.redirectTo({
  //     url: `/pages/user/index`
  //   })
  // }



  return (
    <View className='user'>
      <View className="infoBox">
        <View className="infoLine">
          <View className="label">头像</View>
          <View className="space"></View>
          <Image src={userInfo.avatar} className='avatar' />
          {/* <Image src={Next} className='next' /> */}
        </View>
        <View className="infoLine" onClick={goEdit}>
          <View className="label">昵称</View>
          <View className="space"></View>
          <View className="content">{userInfo.nickname}</View>
          <Image src={Next} className='next' />
        </View>
        {/* <View className="infoLine">
          <View className="label">性别</View>
          <View className="space"></View>
          <View className="content">
            <Picker mode='selector' range={SexSelector} onChange={handleSex}>
              <View className='picker'>
                {SexStatus[userInfo.gender]}
              </View>
            </Picker>
          </View>
          <Image src={Next} className='next' />
        </View> */}
      </View>
      {/* <View className="logout" onClick={logout}>退出登录</View> */}
    </View>
  )
}

User.config = {
  navigationBarTitleText: '个人信息',
}

export default User;
